{layout name="../common/master"/}

<script src="__PUBLIC__/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/uploadify/uploadify.css">

<div id="right">
    <h4 style="border-bottom: 1px solid #ccc;padding-bottom: 3px">添加banner</h4>
    <div id="app">
        <form action="javascript:;" method="post" role="form" class="col-lg-6">
            <div class="form-group">
                <label for="">标题</label>
                <input type="text" class="form-control" required value="{$oldData['title']}"  name="title"  placeholder="请输入标题">
            </div>
            <div class="form-group">
                <label for="">权重</label>
                <input type="text" class="form-control" value="{$oldData['sort']}" name="sort"  placeholder="请输入产品权重">
            </div>
            <div class="form-group">
                <label for="">URL</label>
                <input type="text" class="form-control" value="{$oldData['url']}" name="url"  placeholder="请输入产品权重">
            </div>
            <img style="width: 400px;height: 300px;" src="{$oldData['img_path']}" alt="">
            <div class="form-group">

                <label for="">上传图片</label>
                <input type="file" id="imgcontent" class="form-control"  name="imgcontent"  placeholder="请输入产品权重">
            </div>
            <div class="form-group">
                <label for="">使用平台</label>
                <select name="plantForm" id="inputID" class="form-control">
                    <option value=""> -- Select One --</option>
                    <option {if condition="$oldData['plantForm'] eq 'index'"}selected{/if} value="index">index</option>
                    <option {if condition="$oldData['plantForm'] eq 'coupon'"}selected{/if} value="coupon">coupon</option>
                    <option {if condition="$oldData['plantForm'] eq 'friend'"}selected{/if} value="friend">friend</option>
                </select>
            </div>
            <div class="form-group">
                <label for="">是否有效</label>
                <div class="radio">
                    <label>
                        <input type="radio" name="is_valid" value="1" {if condition="$oldData['is_valid'] eq '1'"}checked="checked"{/if} >
                        有效
                    </label>
                    <label>
                        <input type="radio" name="is_valid" value="0" {if condition="$oldData['is_valid'] eq '0'"}checked="checked"{/if}>
                        无效
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label for="">活动开始时间</label>
                <input name="start_time" type="text" value="{$oldData['start_time']}"  onclick="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
            </div>
            <div class="form-group">
                <label for="">活动结束时间</label>
                <input name="end_time" type="text" value="{$oldData['end_time']}"  onclick="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
            </div>
            <div class="form-group">
                <label for="">备注</label>
                <br/>
                <textarea id="uremark" name="comment"  cols="10" rows="3">{$oldData['comment']}</textarea>
            </div>
            <button type="submit" id="form_submit" class="btn btn-primary">提交</button>
        </form>
    </div>
</div>
<script>
    $("#form_submit").click(function () {
        var title=$("input[name='title']").val();
        var sort=$("input[name='sort']").val();
        var url=$("input[name='url']").val();
        var plantForm=$("#inputID option:selected").val();
        var is_valid=$("input[name='is_valid']").val();
        var start_time=$("input[name='start_time']").val();
        var end_time=$("input[name='end_time']").val();
        var imgcontent=$("#imgcontent")[0].files[0];
        var comment=$("textarea").val();
        var requrl="{:URL('home/Active/editBanner')}";
        var uid="{$_GET['uid']}";
        uploadFile();
        console.log(imgcontent);
        function uploadFile(target) {
            var fm = new FormData();
            fm.append('title', title);
            fm.append('uid', uid);
            fm.append('sort', sort);
            fm.append('url', url);
            fm.append('plantForm', plantForm);
            fm.append('is_valid', is_valid);
            fm.append('comment', comment);
            fm.append('file', imgcontent);
            fm.append('start_time', start_time);
            fm.append('end_time', end_time);
            var xhr = new XMLHttpRequest();
            xhr.upload.addEventListener("progress", uploadProgress, false);
            xhr.addEventListener("load", uploadComplete, false);
            xhr.addEventListener("error", uploadFailed, false);
            xhr.addEventListener("abort", uploadCanceled, false);
            xhr.open("POST", requrl);
            xhr.send(fm);
        }
        function uploadProgress(evt) {
            if (evt.lengthComputable) {
                var percentComplete = Math.round(evt.loaded * 100 / evt.total);
                console.log(percentComplete.toString());
//                $("#loading").show();
//                $("#loading").html(percentComplete.toString() + '%');
            }
            else {
                layer.msg('不能计算百分比');
            }
        }
        function uploadComplete(evt) {
            console.log(evt.currentTarget.response);
            var res=evt.currentTarget.response;
            res=JSON.parse(res);
            if(res.code==0){
                layer.alert('修改成功');
                location.href="{:URL('home/Active/bannerList')}";
            }else{
                layer.msg(res.msg,function(){});
            }
        }
        function uploadFailed(evt) {
            alert("There was an error attempting to upload the file.");
        }
        function uploadCanceled(evt) {
            alert("The upload has been canceled by the user or the browser dropped the connection.");
        }
    })


</script>
<script type="text/javascript" src="__PUBLIC__/home/tuo/DatePicker/WdatePicker.js"></script>

